package com.example.myibatis.junit;


import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.example.myibatis.bean.Student;

public class selectDemo {

	private static String configXML = "Configuration.xml";
	SqlSessionFactory sessionFactory = null;
	@Before
	public void setUp() throws Exception {
		
		Reader reader = Resources.getResourceAsReader(configXML);
		
		sessionFactory = new SqlSessionFactoryBuilder().build(reader);
	}

	@After
	public void tearDown() throws Exception {
	}
	
	
	@SuppressWarnings("rawtypes")
	@Test
	public void selectA(){
/*		SqlSession sqlSession = sessionFactory.openSession();
		List lst = sqlSession.selectList("selectById");
		System.out.println(lst.get(0));*/
		System.out.println("---->>"+sessionFactory.getConfiguration().getMappedStatement("selectById").getBoundSql("selectById").getSql());
		
		
		 
		
		
	}
	@SuppressWarnings("rawtypes")
	@Test
	public void selectCount(){
		SqlSession sqlSession = sessionFactory.openSession();
		Object obj = sqlSession.selectOne("selectCount");
		System.out.println(obj);
	}
	@SuppressWarnings("rawtypes")
	@Test
	public void insertStudent(){
		Student stu = new Student();
		stu.setAge(25);
		stu.setClasses("3(2)");
		stu.setName("姓名333");
		stu.setPid("333");
		stu.setSex("男");
		
		
		SqlSession sqlSession = sessionFactory.openSession();
		Object obj = sqlSession.insert("insertvalues", stu);
		
		sqlSession.commit();
		System.out.println(obj);
	}
	@SuppressWarnings("rawtypes")
	@Test
	public void mapperTest(){
		
		
		SqlSession sqlSession = sessionFactory.openSession();
		Student stud = sqlSession.getMapper(Student.class);
	}

}
